﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using MySql.Data.Common;
using MySql.Data.MySqlClient;

public partial class MySqlTest : System.Web.UI.Page
{
    protected string connectionString = ConfigurationManager.ConnectionStrings["MySqlConnectionString"].ConnectionString;
    
    protected void Page_Load(object sender, EventArgs e)
    {
        InitData();
    }
    private void InitData()
    {
        MySqlConnection con = new MySqlConnection(connectionString);
        MySqlCommand cmd = new MySqlCommand("select ID, Name from city where id < 5", con);
        try
        {
            con.Open();
            MySqlDataReader reader = cmd.ExecuteReader();
            while (reader.Read())
            {
                lblMsg.Text += "id=" + reader[0].ToString() + ", name=" + reader[1].ToString() + "<br />";
            }
            reader.Close();
        }
        catch (MySqlException me)
        {
            lblMsg.Text = me.Message;
        }
        finally
        {
            con.Close();
        }        
        
    }
}
